//
//  QCWelcomeViewController.swift
//  SwiftDemoWithSina
//
//  Created by qu on 2017/2/4.
//  Copyright © 2017年 Apple. All rights reserved.
//

import UIKit
import SDWebImage

class QCWelcomeViewController: UIViewController {

    override func loadView() {
    view = bgImageView
    }
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

        self.headImageView.snp.updateConstraints { (make) in
            make.top.equalToSuperview().offset(100)
        }
     
      UIView.animate(withDuration: 2, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { ()->() in
        
        self.view.layoutIfNeeded()
        
        
      },completion:{ (_) in
        UIView.animate(withDuration: 0.25, animations: { 
            self.messageLabel.alpha = 1
        }, completion: {(_) in
    
            NotificationCenter.default.post(name: NSNotification.Name(rawValue: SWITCHROOTVIEWCONTROLLERNOTI), object: "welcomeVc")
            
        })
   })
}
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupUI()
    }
    
    //MARK: - 设置视图
    private func setupUI(){
        // 01 添加控件
        view.addSubview(headImageView)
        view.addSubview(messageLabel)
        // 02 添加约束

        headImageView.snp.makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 90, height: 90))
            make.top.equalToSuperview().offset(400)
            make.centerX.equalToSuperview()
        }
        
        messageLabel.snp.makeConstraints { (make) in
            make.top.equalTo(headImageView.snp.bottom).offset(16)
            make.centerX.equalTo(headImageView)
        }
        
    }
    private lazy var bgImageView: UIImageView = UIImageView(imageName:"ad_background")
    
    private lazy var headImageView: UIImageView = {
       
        let image = UIImageView(imageName:"avatar_default")
        image.layer.cornerRadius = 45
        image.layer.masksToBounds = true
        image.layer.borderColor = KCOlOR.cgColor
        image.layer.borderWidth = 1
       
        image.setImage(urlString: QCOAuthViewModel.shared.userAccountModel?.avatar_large)
        
        return image
    }()
    private lazy var messageLabel: UILabel = {
       
       let lab = UILabel()
        lab.text = "忍者无敌"
        lab.textAlignment = .center
        lab.alpha = 0
        return lab
    }()

}
